package com.songcha.sakura.util


import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.songcha.sakura.bean.ComicListBean
import com.songcha.sakura.mvp.view.dialog.ComicDetailDialogP
import com.songcha.sakura.mvvm.comic.search.ComicSearchActivity
import com.songcha.sakura.ui.activity.VideoActivity


class MyJumpUtil {
    companion object{
        //private var mComicDetailDialog:SoftReference<ComicDetailDialog>?=null
        //private var mComicDetailDialog:ComicDetailDialogP?=null

        @JvmStatic
         fun toVideo(context: Context, url:String,title:String,isLocal:Boolean=false){
             //val intent= Intent(context, VideoActivity::class.java)
             val intent= Intent(context, VideoActivity::class.java)
             intent.putExtra("url",url)
             intent.putExtra("title",title)
             intent.putExtra("isLocal",isLocal)
             //LogUtil.log(bean.m3u8Url)
             context.startActivity(intent)
        }

        /*fun toMain(context: Context){
            val intent=Intent(context, MainActivity::class.java)
            context.startActivity(intent)
        }*/
        @JvmStatic
        fun toActivity(context: Context,cls:Class<*>){
            val intent=Intent(context, cls)
            context.startActivity(intent)
        }

        @JvmStatic
        fun toSearchComic(context:Context,key:String){
            val intent=Intent(context, ComicSearchActivity::class.java)
            intent.putExtra("key",key)
            context.startActivity(intent)
        }

        @JvmStatic
        fun toComicDetail(context:Context,comic: ComicListBean.ComicBean){

            if(comic.href.isEmpty()) return

            /*if(mComicDetailDialog==null){
                mComicDetailDialog=ComicDetailDialogP(context,comic)
            }else{
                mComicDetailDialog!!.initCtx(context)
            }

            if(context is Fragment){
                mComicDetailDialog!!.show(context.childFragmentManager ,"ComicDetailDialog")
            }else if(context is FragmentActivity){
                mComicDetailDialog!!.show(context.supportFragmentManager ,"ComicDetailDialog")
            }*/

            val dialog = ComicDetailDialogP()
            val bundle=Bundle()
            bundle.putSerializable("comic",comic)
            dialog.arguments=bundle

            if(context is Fragment){
                dialog.show(context.childFragmentManager ,"ComicDetailDialog")
            }else if(context is FragmentActivity){
                dialog.show((context).supportFragmentManager ,"ComicDetailDialog")
            }


            /*val dialog= CustomDialog.Companion.Builder(context)
                .setTitle("提示")
                .setMsg("内容")
            dialog.show()*/


           /* val intent= Intent(context, TestActivity::class.java)
            intent.putExtra("comic",comic)
            context.startActivity(intent)*/


        }
    }
}